// service 统一出口
import Request from './request'
import { BASE_URL, TIEE_OUT } from './request/config'
import { localCache } from '@/utils'

const request = new Request({
  baseURL: BASE_URL,
  timeout: TIEE_OUT,
  interceptors: {
    requestInterceptor: (config) => {
      const token = localCache.getCache('token')
      if (config.headers && token) {
        config.headers.Authorization = `Bearer ${token}`
      }

      return config
    },
    responseInterceptorCatch: (err) => {
      return err
    },
    responseInterceptor: (res) => {
      return res
    },
    requestInterceptorCatch: (err) => {
      return err
    }
  }
})

export default request
